package com.qf.service.impl;

import com.qf.base.DynamicDataSourceContextHolder;
import com.qf.base.QFDataSource;
import com.qf.demo.dto.UserDto;
import com.qf.demo.enums.DataSourceType;
import com.qf.demo.order.Order;
import com.qf.demo.user.User;
import com.qf.mapper.db1.OrderMapper;
import com.qf.mapper.db2.UserMapper;
import com.qf.service.IOrderService;
import com.qf.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class IUserServiceImpl implements IUserService {

     @Autowired
     private UserMapper userMapper;

     @Autowired
     private OrderMapper orderMapper;
     @Autowired
     private IOrderService iOrderService;


    /**
     * 添加上数据
     *
     * @param userDto
     * @return
     */
    @QFDataSource(DataSourceType.primaryDataSource)
    @Override
    public User createUser(UserDto userDto) {
        User user = new User();
        user.setName(userDto.getName());
        user.setEmail(userDto.getEmail());
        userMapper.insert(user);
        iOrderService.createOrder();
        return user;
    }


}
